<template>
  <div>
    <input type="text" v-model="txt">
    <button @click="handleAdd">添加</button>
  </div>
</template>

<script>
//辅助函数，简化调用vuex里面方式
import {mapMutations} from 'vuex'
export default {
  data() {
    return {
      txt: ""
    }
  },
  methods: {
    ...mapMutations(['addItem']),
    handleAdd() {
      // this.$store.commit("addItem", {
      //   id:new Date().getTime().toString(16),
      //   name:this.txt
      // })
      this.addItem({
        id:new Date().getTime().toString(16),
        name:this.txt
      })
    }
  }
}
</script>

